package com.oocl.aeat.listener;

import java.sql.SQLException;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.oocl.aeat.jms.JMSConsumer;
import com.oocl.aeat.jms.JMSProducer;
import com.oocl.aeat.redis.MerchantCache;
import com.oocl.aeat.redis.VerifyCache;
import com.oocl.aeat.util.DataSourceUtils;
import com.oocl.aeat.util.ServerConfig;

public class BasicServletContextListener implements ServletContextListener {


    public BasicServletContextListener() {}

    public void contextInitialized(ServletContextEvent sce) {
    	JMSProducer.init();
		JMSConsumer.setRootPath( ServerConfig.NGINX_IMAGE_LOCAL_PATH );
    	JMSConsumer.startServer();
    	
    	//启动缓存
    	MerchantCache.init();
    	VerifyCache.init();
    }

    public void contextDestroyed(ServletContextEvent sce) {
    	JMSProducer.destroy();
    	JMSConsumer.stopServer();
    	try {
			DataSourceUtils.getDataSource().close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }
	
}
